package com.xyazm.order.remote;

import com.xyazm.common.core.JsonResult;
import com.xyazm.common.utils.CheckResultUtil;
import com.xyazm.product.api.IProductSkuApi;
import com.xyazm.product.domain.dto.ProductSkuDTO;
import com.xyazm.product.domain.param.QueryProductSkuListParam;
import com.xyazm.product.domain.param.QueryProductSkuParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品服务远程调用接口
 * @author xuyou
 * @date 2022年08月25日 8:18
 */
@Component
public class ProductRemote {

    /**
     * 商品服务
     */
    @DubboReference(version = "1.0.0")
    private IProductSkuApi productSkuApi;


    /**
     * 查询商品信息
     * @author xuyou
     * 2022-08-25 8:21
     * @param skuCode 商品编码
     * @param sellerId 卖家id
     * @return com.xyazm.market.domain.dto.ProductSkuDTO
    */
    public ProductSkuDTO getProductSku(String skuCode, String sellerId) {
        QueryProductSkuParam queryProductSkuParam = new QueryProductSkuParam();
        queryProductSkuParam.setSkuCode(skuCode);
        queryProductSkuParam.setSellerId(sellerId);
        JsonResult<ProductSkuDTO> jsonResult = productSkuApi.getProductSku(queryProductSkuParam);
        // 检查api调用结果
        CheckResultUtil.checkResult(jsonResult,"查询商品SKU详情");
        ProductSkuDTO productSkuDTO = jsonResult.getData();
        return productSkuDTO;
    }



    /**
     * 批量查询商品信息
     * @author xuyou
     * 2022-08-25 8:23
     * @param skuCodeList 商品编码集合
     * @param sellerId 卖家id
     * @return java.util.List<com.xyazm.market.domain.dto.ProductSkuDTO>
    */
    public List<ProductSkuDTO> listProductSkus(List<String> skuCodeList, String sellerId) {
        QueryProductSkuListParam param = new QueryProductSkuListParam();
        param.setSkuCodeList(skuCodeList);
        param.setSellerId(sellerId);
        JsonResult<List<ProductSkuDTO>> jsonResult = productSkuApi.listProductSkus(param);
        CheckResultUtil.checkResult(jsonResult,"批量查询商品SKU详情");
        return jsonResult.getData();
    }

}
